package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Category;
import com.cskaoyan.bean.wx.vo.IndexGoodsList;
import com.cskaoyan.mapper.CategoryMapper;
import com.cskaoyan.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author
 * @date 2020/12/9 22:02
 */
@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {
    @Autowired
    GoodsService goodsService;
    @Autowired
    CategoryMapper categoryMapper;

    @RequestMapping("count")
    public BaseRespVo count(){
        Long count =goodsService.countGoods();
        HashMap<String, Long> map = new HashMap<>();
        map.put("goodsCount",count);
        return BaseRespVo.ok(map);
    }

    @RequestMapping("category")
    public BaseRespVo category(Integer id){
        HashMap<String, Object> map = new HashMap<>();
        String level = goodsService.selectLevel(id);
        Integer categoryId =id;
        if (level.equals("L1")) {
            categoryId = goodsService.selectSonCategoryId(id);
        }else if (level.equals("L2")){
            categoryId =id;
        }
        Category currentCategory = goodsService.selectCurrentCategory(categoryId);
        map.put("currentCategory",currentCategory);
        Category parentCategory =goodsService.selectParentCategory(categoryId);
        map.put("parentCategory",parentCategory);
        List<Category> brotherCategory = goodsService.selectBrotherCategory(categoryId);
        map.put("brotherCategory",brotherCategory);
        return BaseRespVo.ok(map);
    }

    @RequestMapping("list")
    public BaseRespVo list(Integer categoryId,Integer page , Integer size ){

        HashMap<String, Object> map =goodsService.selectGoodsList(categoryId,page,size);
        List<Category> filterCategoryList = goodsService.selectBrotherCategory(categoryId);
        map.put("filterCategoryList",filterCategoryList);

        return BaseRespVo.ok(map);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id){

        HashMap<String, Object> map = goodsService.wxGoodsDetail(id);
        return BaseRespVo.ok(map);
    }


    @RequestMapping("related")
    public BaseRespVo related(Integer id){
        List<IndexGoodsList> goodsList= goodsService.selectRelatedGoodsList(id);
        return BaseRespVo.ok(goodsList);
    }



}
